package com.example.exception;

import com.example.common.Rust;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ResponseBody
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public <T>Rust<T> ExceptionHandler(Exception e){
        //判断是否是自己定义的异常
        if(e instanceof SelfException){
            SelfException selfException = (SelfException)e;
            return Rust.error(SelfExceptionEnum.SELF_EXCEPTION_NULL);
        }
        //如果不是返回500
        return Rust.error(SelfExceptionEnum.SELF_EXCEPTION_ORDER);
    }
}
